package com.quanquan.store.controller;


import DTO.user.UserDTO;
import com.quanquan.store.entity.GroupBuying;
import com.quanquan.store.entity.GroupBuyingTradingRecord;
import com.quanquan.store.request.GroupBuyingRequestBody;
import com.quanquan.store.request.GroupBuyingTradingRecordRequestBody;
import com.quanquan.store.service.GroupBuyingTradingRecordService;
import enums.ResCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import web.response.ResultBody;

import java.util.List;

@RestController
@RequestMapping("/group_buying_trading_record")
public class GroupBuyingTradingRecordController {

private final GroupBuyingTradingRecordService groupBuyingTradingRecordService;

    public GroupBuyingTradingRecordController(GroupBuyingTradingRecordService groupBuyingTradingRecordService) {
        this.groupBuyingTradingRecordService = groupBuyingTradingRecordService;
    }

    /**
     * 前端查询团购参与用户详情
     *
     * @param requestBody
     * @return
     */
    @PostMapping("/find_head_img")
    @ResponseBody
    public ResultBody findHeadImg(@RequestBody GroupBuyingTradingRecordRequestBody requestBody) {
        //查询参与用的头像
        Integer page = requestBody.getPage() == null ? 0 : requestBody.getPage();
        Integer size = requestBody.getSize() == null ? 100 : requestBody.getSize();
        String groupBuyingId = requestBody.getGroupBuyingId();
        List<UserDTO> headImg = groupBuyingTradingRecordService.findHeadImg(page, size, groupBuyingId);
        return new ResultBody(ResCodeEnum.SUCCESS.getCode(), ResCodeEnum.SUCCESS.getMsg(), com.alibaba.fastjson.JSONObject.toJSON(headImg));
    }

    /**
     * 参与记录 两种状态，已成团，未成团，已付款
     * @return
     */
    @PostMapping("/query")
    public ResultBody queryTradingRecord(@RequestBody GroupBuyingTradingRecordRequestBody requestBody){
        Integer page = requestBody.getPage() == null ? 0 : requestBody.getPage();
        Integer size = requestBody.getSize() == null ? 100 : requestBody.getSize();
        String userId = requestBody.getUserId();
        List<GroupBuying> groupBuyings = groupBuyingTradingRecordService.queryAllRecord(userId,page,size);
        return new ResultBody(ResCodeEnum.SUCCESS.getCode(), ResCodeEnum.SUCCESS.getMsg(), com.alibaba.fastjson.JSONObject.toJSON(groupBuyings));

    }
}
